package pers.wq.model.dao.core;

import java.util.List;
import java.util.Map;

import org.hibernate.Session;
import org.hibernate.query.NativeQuery;
import org.hibernate.SQLQuery;
import org.hibernate.criterion.CriteriaSpecification;

public class QueryDao {
	public static <T> List<T> query(String str,Class t){
		List<T> reList = null;
		try {
			Session session = HibernateUtil.getSession();
			SQLQuery query = session.createSQLQuery(str);
			reList = query.addEntity(t).list();
			System.out.println(reList);
			//session.flush();
			session.close();
		}catch(Exception e) {
			e.printStackTrace();
			reList = null;
		}
		return reList;
	}
	
	public static List<Map<String,String>> query(String str){
		List<Map<String,String>> reList = null;
		try {
			Session session = HibernateUtil.getSession();
			reList = session.createSQLQuery(str).setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP).list();
			System.out.println(reList);
			//session.flush();
			session.close();
		}catch(Exception e) {
			e.printStackTrace();
			reList = null;
		}
		return reList;
	}
}
